package net.xiduth.game.player.dialogues.tutorial;

import net.xiduth.cores.CoresManager;
import net.xiduth.game.WorldTile;
import net.xiduth.game.player.Player;
import net.xiduth.game.player.Skills;
import net.xiduth.game.player.content.FadingScreen;
import net.xiduth.game.player.content.Magic;
import net.xiduth.game.player.dialogues.Dialogue;
import net.xiduth.utils.Logger;

/**
 * 
 * Final tutorial.
 *
 */

public class Nasaroth extends Dialogue {

	@Override
	public void start() {
	if (!player.isCombatTutorial()) {
			sendNPCDialogue(6539, 9827,
					"Hello "+player.getDisplayName()+".");
		} else {
			sendNPCDialogue(6539, 9827,
					"Welcome back.");
		}	
	}
	
	public void fade (final Player player) {
		final long time = FadingScreen.fade(player);
		CoresManager.slowExecutor.execute(new Runnable() {
		@Override
		public void run() {
		try {
		FadingScreen.unfade(player, time, new Runnable() {
		@Override
		public void run() {
		}
		});
		} catch (Throwable e) {
		Logger.handle(e);
		}
		}

		});
		}

	@Override
	public void run(int interfaceId, int componentId) {
		switch (stage) {
		case -1:
			if (!player.isCombatTutorial()){
				stage = 0;
				sendPlayerDialogue(9827, "Hello.");
			} else {
				stage = 11;
				sendPlayerDialogue(9827, "I'm done!");
			}
			break;
		case 0:
			sendNPCDialogue(6539, 9827, "Firstly, I'd like to tell you "+"congratulations.");
			stage = 1;
			break;
		case 1:
			sendNPCDialogue(6539, 9827, "You're starting to get famous around here, "+player.getDisplayName()+". Ready for your next lesson?");
			stage = 2;
			break;
		case 2:
		sendOptionsDialogue(SEND_DEFAULT_OPTIONS_TITLE,
					"Absolutely!", "What will I need?",
					"Sorry, I'm busy right now.");
		case 3:
		switch (componentId) {
			case OPTION_1:
				sendPlayerDialogue(9827,
						"Bring it on!");
				stage = 4;
				break;
			case OPTION_2:
				sendPlayerDialogue(9827,
						"What should I carry during this mission?");
				stage = 5;
				break;
			case OPTION_3:
				stage = 69;
				sendPlayerDialogue(9827,
						"Sorry I'm busy right now.");
				break;
			}
			break;
		case 4:
			sendNPCDialogue(6539, 9827, "Hmm...");
				stage = 6;
				break;
		case 5:
			sendNPCDialogue(6539, 9827, "You should go smith yourself some weapons and armour.");
				stage = 7;
				break;
		case 6:
			sendNPCDialogue(6539, 9827, "Alright, here we go. Today's lesson will be on combat.");
			stage = 8;
			break;
		case 7:
			sendPlayerDialogue(9827, "Alright.. thanks.");
			stage = 2;
			break;
		case 8:
			fade(player);
			sendNPCDialogue(6539, 9827, "Give the instructors a visit, "+ "to receive your gear.");
			player.lock();
			player.setNextWorldTile(new WorldTile (3209, 3253, 0));
			stage = 9;
			break;
		case 9:
			fade(player);
			sendNPCDialogue(6539, 9827, "For this task, "+"you will need to learn how to kill. I suggest hunting here.");
			player.setNextWorldTile(new WorldTile (3255, 3256, 0));
			stage = 10;
			break;
		case 10:
			fade(player);
			sendNPCDialogue(6539, 9827, "Come back when you have raised your Strength, Magic, and Ranged levels to 15.");
			player.setNextWorldTile(new WorldTile (3209, 3253, 0));
			player.setCombatTutorial();
			player.unlock();
			stage = 70;
			break;
		case 11:
			if (player.getSkills().getLevelForXp(Skills.STRENGTH) > 14
				&& player.getSkills().getLevelForXp(Skills.MAGIC) > 14
				&& player.getSkills().getLevelForXp(Skills.RANGE) > 14) {
			sendNPCDialogue(6539, 9827,
			"Looking fit, "+player.getDisplayName()+"!");
			stage = 12;
			} else { 
			sendNPCDialogue(6539, 9827,
					"Your Strength, Magic, and Range levels must be 15! "+"Get back to work!");
			stage = 69;
			}
			break;		
		case 12:
				sendNPCDialogue(6539, 9827, "Very impressive...");
					stage = 13;
					break;
		case 13:
			sendNPCDialogue(6539, 9827, "We haven't seen a trainee like you in ages...");
				stage = 14;
				break;
		case 14:
			sendPlayerDialogue(9827, "Really? That means a lot to me.");
				stage = 15;
				break;
		case 15:
			sendNPCDialogue(6539, 9827, "It should.");
				stage = 16;
				break;
		case 16:
			sendNPCDialogue(6539, 9827, "Your training is now complete.");
				stage = 17;
				break;
		case 17:
			sendNPCDialogue(6539, 9827, "Go out and explore the vast world of Xiduth!");
				stage = 18;
				break;
		case 18:
					player.getInventory().addItem(6099, 1);
					player.setDoneCombatTutorial();
					player.falseCombatTutorial();
					player.getControlerManager().removeControlerWithoutCheck();
					Magic.sendNormalTeleportSpell(player, 0, 0, new WorldTile(3682,
							2973, 0));
		            	player.getInterfaceManager().sendInterface(275);
						for (int i = 0; i < 310; i++) {
							player.getPackets().sendIComponentText(275, i, "");
							player.getPackets().sendIComponentText(275, 1, "Quest Complete!</col>");
							player.getPackets().sendIComponentText(275, 13, "You have finished the tutorial.");
							player.getPackets().sendIComponentText(275, 14, "Limits have been lifted.");
							player.getPackets().sendIComponentText(275, 16, "Teleport Crystal access.");
							}
						 player.getInterfaceManager().closeChatBoxInterface();
                stage = 69;
                break;
		case 69:
			end();
			break;
		case 70:
			end();
			break;
		case -2:
			end();
			break;
	}
}

		@Override
	public void finish() {
		// TODO Auto-generated method stub

	}
}